package dreampack.dataQuery;

import java.sql.*;

import dreampack.*;
import dreampack.dataType.*;

public class SubjectQuery {
	public SubjectQuery(){}
	
	public static SubjectType queryById(DreamDB dreamDb, int id) throws Exception{
		SubjectType subject = null;
		Connection con = null;
		PreparedStatement prepStmt = null;
		ResultSet rs = null;
		
		try{
			con = dreamDb.getConnection();
			String selectStatement = "select * from t_subject where id=?";
			prepStmt = con.prepareStatement(selectStatement);
			prepStmt.setInt(1, id);
			rs = prepStmt.executeQuery();
			if (rs.next()) {
				subject = new SubjectType();
				subject.init(rs);
				return subject;
			}
			else
				return null;
		}finally{
			dreamDb.closeResultSet(rs);
			dreamDb.closeStatement(prepStmt);
			dreamDb.closeConnection(con);
		}
	}
}
